<template>
	<view class="content">
		<cu-custom bgColor="uerHead1" :isBack="true" textRight="true" type="1" @clickRight="save()">
			<block slot="backText" class="titilestyle">{{title}}</block>
			<block slot="right" class="" @click="save"><text class="text-blod text-blue">保存</text></block>
		</cu-custom>



		<scroll-view scroll-y="true">


			<view class="inro-card  flex  flex-direction margin-top">
				<view class="flex inro-card-fill  flex-wrap ">
					<view class="basis-xll margin-xs  text-cut text-gray">
						*公司名称
					</view>

					<view class="basis-xll margin-xs   ">
						<input class=" " placeholder="输入公司名称" value="" name="input" v-model="postData.company_name"></input>
					</view>
				</view>
				<view class="flex inro-card-fill flex-wrap solid-top">
					<view class="basis-xll margin-xs  text-cut text-gray">
						*所在职位
					</view>

					<view class="basis-xll margin-xs   ">
						<input class=" " placeholder="请填写您在该公司的职位" v-model="postData.job" value="" name="input"></input>
					</view>
				</view>
				<view class="flex inro-card-fill flex-wrap solid-top">
					<view class="basis-xll margin-xs  text-cut text-gray">
						*在职时间
					</view>

					<view class="basis-xll margin-xs text-xl flex ">
						<view class="basis-sm ">
							<picker mode="date" :value="postData.start_at" @change="DateChange($event,'start_at')">
								<view class=" flex  justify-between">
									<view class="">
										<text class="text-gray" v-if="postData.start_at==''">请选择开始时间</text>
										<text v-else>{{postData.start_at}}</text>
									</view>
									<view class="">
										<text class="cuIcon-right"></text>
									</view>
								</view>

							</picker>
						</view>

						<view class="basis-xs text-center   radius">
							至
						</view>

						<view class="basis-sm ">
							<picker mode="date" :value="postData.endTime" :start="postData.start_at"
								@change="DateChange($event,'end_at')">
								<view class=" flex  justify-between">
									<view class="">
										<text class="text-gray" v-if="postData.end_at==''">请选择结束时间</text>
										<text v-else>{{postData.end_at}}</text>
									</view>
									<view class="">
										<text class="cuIcon-right"></text>
									</view>
								</view>

							</picker>
						</view>
					</view>
				</view>

			<view class="flex inro-card-fill flex-wrap solid-top">
				<view class="basis-xll margin-xs  text-cut text-gray">
					*工作内容
				</view>
			
				<view class="basis-xll margin-xs">
					<textarea maxlength="100" style="width: 100%;" placeholder="请输入工作内容"
						v-model="postData.desc"></textarea>
			
				</view>
			
				<view class="basis-xll flex justify-end">
					{{postData.desc.length}}/{{100}}
				</view>
			</view>
			
				
				
				
				
				
				
				
			</view>
			
			
			

			<view class="padding flex basis-xl flex-wrap middle " v-if="ind!=-1">
				<button class="cu-btn lg bg-blue" style="width: 92%;" @click="del">删除该经历</button>
			</view>


		</scroll-view>




	</view>
</template>

<script>
	export default {

		data() {

			return {
				title: "工作经历",
				postData:{
					company_name:"",
					job:"",
					start_at:"",
					end_at:"",
					desc:"",
					work_id:""
				},
				ind:-1
		
				
				




			}
		},
		onLoad(option) {
			
			if(typeof option.index!="undefined"){
				this.ind = option.index;
				this.getReseume();
			}
		
		},
		methods:{
			/**
			 * 获取我的简历
			 */
			getReseume() {
			
				this.apiRequest('/buyer/OfferResume', {
			
				}, "get", 0).then(res => {
					if (res.code == 200) {
						for(let i in this.postData){
			
							if(i=="start_at" || i=="end_at"){
								let a=(res.data.resume.work[this.ind][i]).split(" ");
								res.data.resume.work[this.ind][i]=a[0];
							}
							
							this.postData[i]=res.data.resume.work[this.ind][i];
							
						}
			
					}
			
			
				})
			
			
			
			},
			
			/**
			 * 消失提示
			 * @param {Object} content
			 */
			showToast(content) {
				uni.hideLoading();
				uni.showToast({
					title: content,
					icon: "none"
				});
			
			},
			/**
			 * 选择时间段
			 */
			DateChange(e, type) {
				this.postData[type] = e.detail.value;
			},
			/**
			 * 验证表达式
			 */
			verify(...dat) {
				let val = true,
					da = dat[1][dat[0]];
				console.log(da);
				switch (dat[0]) {
					case "company_name": //关于username的验证
						if (da.length == 0) {
							this.showToast("请输入公司名称");
							val = false;
						}
						break;
					case "job":
						if (da.length == 0) {
							console.log(da)
							this.showToast("请输入所在的职位");
							val = false
						}
						break;
			
					case "start_at":
			
						if (da == "") {
			
							this.showToast("请选择开始时间");
							val = false
						}
						break;
					case "end_at":
			
						if (da == "") {
			
							this.showToast("请选择结束时间");
							val = false
						}
						break;
			
					case "desc":
			
						if (da == "") {
			
							this.showToast("请输入工作内容");
							val = false
						}
						break;
				}
				return val
			},
			
			/**
			 * 保存经历
			 */
			save() {
				let dat = this.postData;
				for (let u in dat) {
					let isPass = this.verify(u, dat);
					if (!isPass) {
						return false;
					}
				}
				this.apiRequest('/buyer/OfferResumeEditWork', this.postData, 1, "post").then(res => {
				
					if (res.code == 200) {
						uni.showToast({
							title:"保存成功",
							icon:"success"
						})
						this.postInfo = res.data.resume.work;
			
					}
				}).catch(() => {
			
				})
			
			
			},
			
			
			del(){
			let d = () => {
				this.apiRequest('/buyer/OfferResumeDelWork', {
					work_id: this.postData.work_id
				}, 1, "DELETE").then(res => {
					if (res.code == 200) {
						uni.showToast({
							title: "删除成功",
							icon: "none"
						})
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							})
						}, 1000);
			
			
			
					}
				}).catch(() => {
			
				})
			}
			
			uni.showModal({
				title: "删除提示",
				content: "确认是否删除该经历？",
				success: (e) => {
					if (e.confirm) {
						d();
					}
				}
			})
			
				
				
			}
		}
		


	}
</script>

<style scoped>
	/**
	 * 卡片样式
	 */
	.inro-card {
		width: 92%;
		margin: 20upx auto;
		background: #FFFFFF;
		box-shadow: 0px 0px 10upx 0px rgba(0, 0, 0, 0.05);
		border-radius: 20upx;
		padding: 30upx;
		position: relative;
	}

	.inro-card-fill {
		width: 100%;
		margin: 20rpx 0 20rpx 0;
		min-height: 100rpx;
	}

	.text-right {
		position: absolute;
		float: right;
		right: 0;
	}

	/* 	picker {
		position: relative;
	} */
</style>
